package com.caocaog.market.finance.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.finance.pay.vo.BillStatistics;
import com.caocaog.market.finance.pay.vo.WithdrawalsRecord;
import com.caocaog.market.finance.service.BillStatisticsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.GenericController;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/bill/statistics")
public class BillStatisticsController extends GenericController<BillStatistics, BillStatisticsService> {


    @GetMapping(value = "/getCanBeWithdrawnAmount")
    public Result<BigDecimal> getCanBeWithdrawnAmount(@RequestParam String shopId) {
        return Result.OK(service.getCanBeWithdrawnAmount(shopId));
    }


    @GetMapping(value = "/getToBeSettledAmount")
    public Result<BigDecimal> getToBeSettledAmount(@RequestParam String shopId) {
        return Result.OK(service.getToBeSettledAmount(shopId));
    }


    @GetMapping(value = "/getSevenDaysSalesRecords")
    public Result<List<BillStatistics>> getSevenDaysSalesRecords(@RequestParam String shopId) {
        return Result.OK(service.getSevenDaysSalesRecords(shopId));
    }


    @GetMapping(value = "/getSalesRecordPage")
    public Result<IPage<BillStatistics>> getSalesRecordPage(@RequestParam String shopId, QueryRequest queryRequest) {
        Page<BillStatistics> page = PageGenerator.createPageSort(queryRequest);
        page.setOrders(new ArrayList<>());
        return Result.OK(service.getSalesRecordPage(page, shopId));
    }


    @GetMapping(value = "/getInvoiceSettledPage")
    public Result<IPage<BillStatistics>> getInvoiceSettledPage(@RequestParam String shopId, QueryRequest queryRequest) {
        Page<BillStatistics> page = PageGenerator.createPageSort(queryRequest);
        page.setOrders(new ArrayList<>());
        return Result.OK(service.getInvoiceSettledPage(page, shopId));
    }


    @GetMapping(value = "/getPendingBillPage")
    public Result<IPage<BillStatistics>> getPendingBillPage(@RequestParam String shopId, QueryRequest queryRequest) {
        Page<BillStatistics> page = PageGenerator.createPageSort(queryRequest);
        page.setOrders(new ArrayList<>());
        return Result.OK(service.getPendingBillPage(page, shopId));
    }


    @GetMapping(value = "/getWithdrawalsRecordPage")
    public Result<IPage<WithdrawalsRecord>> getWithdrawalsRecordPage(@RequestParam String shopId, QueryRequest queryRequest) {
        Page<WithdrawalsRecord> page = PageGenerator.createPageSort(queryRequest);
        page.setOrders(new ArrayList<>());
        return Result.OK(service.getWithdrawalsRecordPage(page, shopId));
    }


}
